package br.com.webcrm.service.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import br.com.webcrm.dao.TipoEnderecoDAO;
import br.com.webcrm.model.TipoEndereco;
import br.com.webcrm.service.TipoEnderecoService;

@Service(value = "tipoEnderecoService")
public class TipoEnderecoServiceImpl extends BaseServiceImpl implements
		TipoEnderecoService, Serializable {

	private static final long serialVersionUID = 2199521492819838428L;

	@Resource
	private TipoEnderecoDAO tipoEnderecoDAO;

	@Override
	public TipoEndereco persistir(TipoEndereco tipoEndereco) throws Exception {
		if (tipoEndereco.getIdTipoEndereco() == null) {
			return gravar(tipoEndereco);
		} else {
			return alterar(tipoEndereco);
		}
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public TipoEndereco gravar(TipoEndereco tipoEndereco) throws Exception {
		return this.tipoEnderecoDAO.gravar(tipoEndereco);
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public TipoEndereco alterar(TipoEndereco tipoEndereco) throws Exception {
		return this.tipoEnderecoDAO.atualizar(tipoEndereco);
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public List<TipoEndereco> consultarTodos() throws Exception {
		return this.tipoEnderecoDAO.consultarTodos();
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public void excluir(TipoEndereco tipoEndereco) throws Exception {
		this.tipoEnderecoDAO.excluir(tipoEndereco);
	}

}
